import axios from 'axios'
axios.defaults.timeout = 5000 //超市时间是5秒
axios.defaults.withCredentials = true //允许跨域
//Content-Type 响应头

//基础url
axios.defaults.baseURL = 'http://localhost:8888'
/**
 * 封装get方法
 */
export function get(url, params = {}) {
  return new Promise((resolve, reject) => {
    axios
      .get(url, { params: params })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

/**
 * 封装post方法
 */
export function post(url, data = {}) {
  return new Promise((resolve, reject) => {
    axios
      .post(url, data)
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}
